import { getPermission } from "@/utils/userToken";

export default {
    inserted(el, binding, vnode) {
        const { value } = binding;
        let permissions = getPermission() ? JSON.parse(getPermission()) : [];
        if (value) {
            const setA = new Set(value);
            const setB = new Set(permissions);
            const hasPermission = new Set([...setA].filter(x => setB.has(x))).size > 0;
            if (!hasPermission) {
                el.parentNode && el.parentNode.removeChild(el);
            }
        } else {
            throw new Error(`need single url! `);
        }
    }
};
